import http from "./http";

/** 获取存储数据 */
export const findAllDrawData = async () => {
  const userData = JSON.parse(localStorage.getItem("userData"));
  return http.get(import.meta.env.VITE_API_DRWA_PREFIX + `/drawdbData/page`, {
    params: { drawdbUserId: userData.id },
  });
};

/** 保存存储数据 */
export const saveDrawData = async (data) => {
  return http.post(import.meta.env.VITE_API_DRWA_PREFIX + `/drawdbData/add`, {
    data,
  });
};

/** 删除存储数据 */
export const deleteDrawData = async (id) => {
  return http.delete(
    import.meta.env.VITE_API_DRWA_PREFIX + `/drawdbData/batch/${id}`,
    {},
  );
};

/** 修改存储数据 */
export const updateDrawData = async (data) => {
  return http.put(import.meta.env.VITE_API_DRWA_PREFIX + `/drawdbData/update`, {
    data,
  });
};

/** 登陆 */
export const login = (data) => {
  return http.post(import.meta.env.VITE_API_DRWA_PREFIX + `/drawdbUser/login`, {
    data,
  });
};

/** 获取用户数据 */
export const findOneDrawdbUserName = (name) => {
  return http.get(
    import.meta.env.VITE_API_DRWA_PREFIX + `/drawdbUser/userName/${name}`,
  );
};

/** 注册 */
export const addDrawdbUser = (data) => {
  return http.post(
    import.meta.env.VITE_API_DRWA_PREFIX + `/drawdbUser/drawdbUserAdd`,
    {
      data,
    },
  );
};

/** 修改用数据 */
export const updateDrawdbUser = (data) => {
  return http.put(
    import.meta.env.VITE_API_DRWA_PREFIX + `/drawdbUser/updateUser`,
    {
      data,
    },
  );
};

/** 获取所有用户数据 */
export const findAllDrawdbUser = () => {
  return http.get(import.meta.env.VITE_API_DRWA_PREFIX + `/drawdbUser/all`);
};

/** 分享 */
export const share = (data) => {
  return http.put(import.meta.env.VITE_API_DRWA_PREFIX + `/drawdbUser/share`, {
    data,
  });
};

/** 获取分享 */
export const getShare = (dataId) => {
  return http.get(import.meta.env.VITE_API_DRWA_PREFIX + `/drawdbUser/share/${dataId}`);
};
